home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / util / conv / MIDI2asm.lha / MIDI2asm.rexx < prev   
OS/2 REXX Batch file  |  1998-02-09  |  3KB  |  121 lines

  1. /* $VER: MIDI2asm 0.9 $ */
  2. /* Convert MIDI data to assembler source */
  3. /* © by Stefan Haubenthal 1998 */
  4. if ~open(midi,arg(1)) then exit 0*writeln(stdout,"Usage: MIDI2asm midifile")
  5. say ";" arg(1) "V"word(sourceline(1),4)
  6. say
  7. say "DELTA    macro"
  8. say "    ifgt    \1-16383"
  9. say "    dc.b    \1>>14|128"
  10. say "    endc"
  11. say "    ifgt    \1-127"
  12. say "    dc.b    \1>>7&$ff|128"
  13. say "    endc"
  14. say "    dc.b    \1&127"
  15. say "    endm"
  16. say "noteoff=$80"
  17. say "noteon=$90"
  18. say "polypress=$A0"
  19. say "ctrl=$B0"
  20. say "prog=$C0"
  21. say "chanpress=$D0"
  22. say "pitchbend=$E0"
  23. say "sysex=$F0"
  24. say "meta=$FF"
  25. /*
  26. say "seqnum=$00"    /* sequence_number  */
  27. say "text=$01"        /* text_event  */
  28. say "copyright=$02"    /* copyright_notice  */
  29. say "sname=$03"        /* sequence_name     */
  30. say "iname=$04"        /* instrument_name  */
  31. say "lyric=$05"        /* lyric         */
  32. say "marker=$06"    /* marker  */
  33. say "cue=$07"        /* cue_point  */
  34. say "cprefix=$20"    /* channel_prefix */
  35. say "trackend=$2f"    /* end_of_track */
  36. say "tempo=$51"        /* set_tempo  */
  37. say "smpte=$54"        /* smpte_offset */
  38. say "time=$58"        /* time_signature */
  39. say "key=$59"        /* key_signature */
  40. say "seqspec=$74"    /* sequencer_specific */
  41. */
  42. say
  43. say "    data"
  44. say '    dc.b    "'readch(midi,4)'"'
  45. say "    dc.l    "c2d(readch(midi,4))
  46. say "    dc.w    "c2d(readch(midi,2)) "format"
  47. tracks=c2d(readch(midi,2))
  48. say "    dc.w    "tracks "tracks"
  49. tempo=c2d(readch(midi,2))*4
  50. say "    dc.w    "tempo/4 "tempo"
  51.  
  52. do track=1 to tracks
  53. say
  54. say "; track" track
  55. say '    dc.b    "'readch(midi,4)'"'
  56. len=c2d(readch(midi,4))
  57. /*say "    dc.l    "len "size"*/
  58. parse value d2x(len,8) with len1 3 len2 5 len3 7 len4
  59. say "    dc.b    $"len1",$"len2",$"len3",$"len4 "size"
  60. time=0
  61. measure=0
  62. do forever
  63.     data=c2d(readch(midi))
  64.     if data<128 then delta=data
  65.     else do
  66.         delta=(data-128)*128
  67.         data=c2d(readch(midi))
  68.         if data<128 then delta=delta+data
  69.         else delta=delta*128+(data-128)*128+c2d(readch(midi))
  70.     end
  71.     time=time+delta
  72.     if time/tempo=measure then do
  73.         say "; measure" time/tempo+1
  74.         measure=measure+1
  75.     end
  76.     say "    DELTA    "delta
  77.     data=c2x(readch(midi))
  78.     select
  79.         when data<"80" then /* short event */
  80.         say "    dc.b    "x2d(data)","c2d(readch(midi))
  81.         when left(data,1)="8" then
  82.         say "    dc.b    noteoff+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
  83.         when left(data,1)="9" then
  84.         say "    dc.b    noteon+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
  85.         when left(data,1)="A" then
  86.         say "    dc.b    polypress+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
  87.         when left(data,1)="B" then
  88.         say "    dc.b    ctrl+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
  89.         when left(data,1)="C" then
  90.         say "    dc.b    prog+"x2d(right(data,1))","c2d(readch(midi))
  91.         when left(data,1)="D" then
  92.         say "    dc.b    chanpress+"x2d(right(data,1))","c2d(readch(midi))
  93.         when left(data,1)="E" then
  94.         say "    dc.b    pitchbend+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
  95.         when data="F0" then do
  96.             len=c2d(readch(midi))
  97.             say "    dc.b    sysex,"len
  98.             call dump
  99.             end
  100.         when data="FF" then do
  101.             data=c2x(readch(midi))
  102.             len=c2d(readch(midi))
  103.             say "    dc.b    meta,$"data","len
  104.                 select
  105.                     when left(data,1)="0" then
  106.                         if len>1 then say '    dc.b    "'readch(midi,len)'"'
  107.                              else call dump
  108.                     when data="2F" then leave
  109.                     otherwise call dump
  110.                 end
  111.             end
  112.     end
  113. end
  114. end
  115. exit
  116.  
  117. dump:
  118. do i=1 to len
  119.     say "    dc.b    $"c2x(readch(midi))
  120. end
  121.